//用户相关的请求接口

import myAxios from '@/utils/config/axiosConfig.ts'
import type { User } from '@/utils/dataType/UserModel'

export const checkToken = async (params: { token: string }) => {
  const res = await myAxios.request({
    url: '/user/user/isLogin',
    method: 'POST',
    params,
  })
  return res
}
/**
 * 用户登录接口,获得token
 * @param user
 * @returns
 */
export const userLogin = async function (user: { username: string; password: string }) {
  const res = await myAxios.request({
    method: 'POST',
    url: '/user/user/login',
    data: user,
  })
  return res
}

/**
 * 用户注册接口
 * @param userInformation
 * @returns
 */
export const userRegister = async function (userInformation: User) {
  const res = await myAxios.request({
    method: 'POST',
    url: '/user/user/register',
    data: userInformation,
  })
  return res
}
/**
 * 用户上传新头像
 * @param file
 */
export const updateUserAvatar = async function (fromData:FormData) {
  const res = await myAxios.request({
    method: 'PUT',
    url: '/user/user/uploadAvatar',
    data: fromData, //body参数
  })
  return res
}
/**
 * 修改用户个人信息
 * @param data
 */
export const updateUserInfor = async (data: {
  username: string
  password: string
  phone: string
  email: string
  name: string
  sex: string
  birthday: string
}) => {
  const res = await myAxios.request({
    url: '/user/user/information',
    method: 'PUT',
    data,
  })
  return res
}
